package com.youhome.api.handler;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * Created by chen365 on 2019/05/27.
 */
@ControllerAdvice
@ResponseBody
public class MyExceptionHandler {
    @ExceptionHandler(CustomException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseEntity<Result> handlerMyException(CustomException e) {
        System.err.println("CustomException==>>" + e.getResultCode().toString());
        return ResponseEntity.ok().body(new Result(e.getResultCode()));
    }
}
